package work20241128;

/**
 * @author zdl
 * @date 2024/11/28
 */
public class Demo12 {
    public static void main(String[] args) {
        //递归
        int s = test(5);
        System.out.println(s);
    }

    public static int test(int num) {
        if (num > 0) {
            /**
             *      5+test(4)
             *      5+4+test(3)
             *      5+4+3+test(2)
             *      5+4+3+2+test(1)
             *      5+4+3+2+1+test(0)
             */
            return num + test(num - 1);
        } else {
            return 0;
        }

    }
}
